import requests
import time
import sys
sys.path.append("../")
from model.StockBaseInfo import *
from frameworks.utils.PrettyTableUtil import *
from frameworks.cores.LoadClass import *
from services.CodesService import *
from services.DayKlineService import *
from frameworks.utils.RedisUtil import *
import json
import time

loader = LoadClass()
redis = RedisUtil()

ck1 = "day_score_cache"
data = redis.vget(ck1)
if data != None:
    objlist = json.loads(data)
    scorelist = reversed(sorted(objlist, key=lambda x: x['score']))
    ordScore = {}
    m = 0
    for obj in scorelist:
        ordScore[obj["code"]] = m
        m += 1
    print(ordScore)

    moneyscorelist = reversed(sorted(objlist, key=lambda x: x['money_score']))
    n = 0
    moneyScore = {}
    for obj in moneyscorelist:
        moneyScore[obj["code"]] = n
        n += 1

    allScorelist = {}
    for key in ordScore.keys():
        allScorelist[key] = ordScore[key] + moneyScore[key]

    optionlist = []
    for row in objlist:
        row["allscore"] = allScorelist[row["code"]]
        optionlist.append(row)

    ck = "day_all_score_cache"
    redis.vset(ck,json.dumps(optionlist))
